package tests.org.nicta.datasetLoader;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.HashSet;

import org.junit.Test;
import org.nicta.datasetLoader.MovieLens.MovieLensDataLoader;;

public class MovieLensDataLoaderUnitTest{

	@Test
	public void testMovieLensDataLoader() throws Exception{
		String datasetType = "100K";
		String ratingsFileLocation = "data/MovieLens/100K/u.data.t";
		String usersFileLocation = "data/MovieLens/100K/u.user";
		String moviesFileLocation = "data/MovieLens/100K/u.item";
		
		HashMap<Integer, double[]> userFeatures;
		HashMap<Integer, double[]> movieFeatures;
		HashMap<Integer[], Double> ratings;
		HashMap<Integer, HashSet<Integer>> userRatedMovies;
		HashMap<Integer, HashSet<Integer>> moviesUsersMap;
		HashMap<Integer, HashMap<Integer, Double>> movieUserRatings;
	
		MovieLensDataLoader loader = new MovieLensDataLoader(datasetType, 
															ratingsFileLocation,
															usersFileLocation,
															moviesFileLocation);
		loader.loadData();
		userFeatures = loader.getUsersFeatures();
		movieFeatures = loader.getMoviesFeatures();
		ratings = loader.getRatings();
		userRatedMovies = loader.getUserRatedMoviesMap();
		moviesUsersMap = loader.getMoviesUsersMap();
		movieUserRatings = loader.getmovieUserRatings();
		
		//Note: test cases are with respect to MovieLens 100K dataset
		
		//check whether the users features are loaded properly 
		assertEquals(userFeatures.size(), 943);
		//check whether the movie features are loaded properly
		assertEquals(movieFeatures.size(), 1682);
		//check whether the ratings are loaded properly
		assertEquals(ratings.size(), 100000);
		//check whether  the userRatedMovies data structure is filled properly
		assertEquals(userRatedMovies.size(), 943);
		//check whether the movieUserMap data structure is filled properly
		assertEquals(moviesUsersMap.size(), 1682);		
		//*Coarse check whether the movieUserMap data structure is filled properly
		assertEquals(movieUserRatings.size(),1682);
	}

}
